package lia.org.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class CommonControl<K> {
	
	/**
	 * Generates modelMap to return in the modelAndView
	 * 
	 * @param contacts
	 * @return
	 */
	protected Map<String, Object> getMap(List<K> contacts) {

		Map<String, Object> modelMap = new HashMap<String, Object>(3);
		modelMap.put("total", contacts.size());
		modelMap.put("data", contacts);
		modelMap.put("success", true);

		return modelMap;
	}
	
	protected Map<String, Object> getMap(List<K> contacts, int size) {

		Map<String, Object> modelMap = new HashMap<String, Object>(3);
		modelMap.put("total", size);
		modelMap.put("data", contacts);
		modelMap.put("success", true);

		return modelMap;
	}

	/**
	 * Generates modelMap to return in the modelAndView in case of exception
	 * 
	 * @param msg
	 *            message
	 * @return
	 */
	protected Map<String, Object> getModelMapError(String msg) {

		Map<String, Object> modelMap = new HashMap<String, Object>(2);
		modelMap.put("message", msg);
		modelMap.put("success", false);

		return modelMap;
	}
	
	protected Map<String, Object> getModelMapSucces(String msg) {

		Map<String, Object> modelMap = new HashMap<String, Object>(2);
		modelMap.put("message", msg);
		modelMap.put("success", true);

		return modelMap;
	}

}
